<?php
declare(strict_types=1);
namespace app\common\widget;
use aphp\core\Widget;
class MemberCount extends Widget
{
    protected string $tag = 'book_member';
    protected int $expire = 0;
    public function set($id = '', array $options = [])
    {
        $uid = session('user.id');
        if (!empty($uid)) {
            $book_ids = db('book')->where('user_id', $uid)->order('id ASC')->column('id');
            if (!empty($book_ids)) {
                return db('book_member')->where('book_id', 'in', $book_ids)->where('status=0 OR is_upgrade=1')->count();
            }
        }
        return 0;
    }
}